﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using wrsm.wow.entity;

namespace wrsm.client {

    /// <summary>
    /// World of Warcraft Installation Details User Control
    /// Dimply displays information from a Wow Install Entity
    /// 
    /// Allows exploring of related entities
    /// </summary>
    public partial class WowInstallDetailsControl : UserControl {

        #region [Local Attributes]

        /// <summary>
        /// Bound Wow Installation Entity
        /// </summary>
        private WowInstallation _install;

        #endregion

        #region [Public Properties]

        /// <summary>
        /// Gets/Sets (binds) Wow installation to user control
        /// </summary>
        public WowInstallation WowInstall {
            get {
                return _install;
            }
            set {
                _install = value;
                RenderBoundInstall();
            }
        }

        #endregion

        #region [Construction]

        /// <summary>
        /// Intialize WowInstallDetailsControl
        /// </summary>
        public WowInstallDetailsControl() {
            InitializeComponent();
        }

        #endregion

        #region [Control Physics]

        /// <summary>
        /// Renders the bound installation to the user control
        /// </summary>
        private void RenderBoundInstall() {
            //Render General details
            txtSelectedPath.Text = _install.InstallLocation;
            txtNumAccounts.Text = GetNumAccounts().ToString();
            txtNumRealms.Text = GetNumRealms().ToString();
            txtNumCharacters.Text = GetNumCharacters().ToString();

            //TODO: Bind to install explorer

        }

        /// <summary>
        /// Returns the number of accounts from bound wow install entity
        /// </summary>
        /// <returns>number of accounts detected</returns>
        private int GetNumAccounts() {
            return _install.Accounts.Length;
        }

        /// <summary>
        /// Returns the number of realms from bound wow install entity
        /// </summary>
        /// <returns>Number of realms detected</returns>
        private int GetNumRealms() {
            int numRealms = 0;
            foreach (var account in _install.Accounts) {
                numRealms += account.Realms.Length;
            }
            return numRealms;
        }

        /// <summary>
        /// Returns the number of characters from bound wow install entity
        /// </summary>
        /// <returns>Number of characters detected</returns>
        private int GetNumCharacters() {
            int numCharacters = 0;
            foreach (var account in _install.Accounts) {
                foreach (var realm in account.Realms) {
                    numCharacters += realm.Characters.Length;
                }
            }
            return numCharacters;
        }

        #endregion

    }
}
